dojo.provide("miaigo.model.sgf.SGFTree");

dojo.declare(
    "miaigo.model.sgf.SGFTree",
    null,
    {
	// A tree is a sequence of nodes
	// miaigo.model.sgf.SGFNode
	_nodes: null,

	// if this tree is a variation of a node, the node is its owner.
	// root tree has no owner.
	// miaigo.model.sgf.SGFNode
	_ownerNode: null,

	constructor: function(createParam)
	{
	    if (createParam)
	    {
		this._ownerNode = createParam.owner;
	    }

	    this._nodes = [];
	},

	getOwner: function() { return this._ownerNode; },
	getParent: function()
	{
	    if (this._ownerNode)
	    {
		return this._ownerNode.getParent();
	    }
	    return null;
	},

	getNodeCount: function() { return this._nodes.length; },
	getNode: function(index) { return this._nodes[index]; },

	// return -1 if the given node is not fount
	// otherwise return index of the given node.
	indexOf: function(/* miaigo.model.sgf.SGFNode */node)
	{
	    return dojo.indexOf(this._nodes, node);
	},

	addNode: function(/* miaigo.mode.sgf.SGFNode */node)
	{
	    if (node.getParent() == this)
	    {
		this._nodes.push(node);
	    }
	    else
	    {
		console.error("SGFTree.addNode: parent is not me!");
	    }
	}
    });